package com.qidian.mes.cal.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.cal.mapper.UserMapper;
import com.qidian.mes.cal.service.UserService;
import com.qidian.mes.pojo.User;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    //根据用户id查询数据
    public MESResult getByUserId(Long userId) {
        return MESResult.ok(userMapper.getByUserId(userId));
    }
    @Override
    //根据部门id查询用户数据
    public MESResult selectByDepartmentId(Long departmentId) {
        return MESResult.ok(userMapper.selectByDepartmentId(departmentId));
    }

    @Override
    //分页查询
    public MESResult list(int page, int limit, User user) {
        // 开启分页 在当前线程中执行下一条SQL的时候就会进行分页。
        PageHelper.startPage(page, limit);
        List<User> userList = userMapper.list(user);
        // 组织一个分页对象。（页码，每页大小，最大页码，数据，总条数）
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        return MESResult.ok(pageInfo);
    }
}
